package application;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;

public class UserData {

    // private String PC_Name; //Current user name + PC local name
    private String userFirstName;
    private String userSecondName;

    private float maxOrderCost;

    private Date makeOrderAllert;
    private Date sendOrdersAllert;
    private Date menuUpdateAllert;

    UserData() {
	FileInputStream fis;
	try {
	    fis = new FileInputStream("Lunchy.cfg");
	    ObjectInputStream ois = new ObjectInputStream(fis);

	    // parsing strings

	    ois.close();
	} catch (Exception e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();

	}

    }

    static public String getPCName() {
	String name = new String("");
	try {
	    name = InetAddress.getLocalHost().getHostName() + ".";
	} catch (UnknownHostException e) {
	    name = "";
	}
	;
	name = name + System.getProperty("user.name");
	return name;
    }

    void saveSettings() {
	File fos;
	BufferedWriter oos;
	StringBuilder sb;
	try {
	    fos = new File("Lunchy.cfg");
	    oos = new BufferedWriter(new FileWriter(fos, true));

	    sb = new StringBuilder();
	    sb.append("userFirstName = ");
	    sb.append(userFirstName);
	    oos.write(sb.toString());

	    sb = new StringBuilder();
	    sb.append("userSecondName = ");
	    sb.append(userSecondName);
	    oos.write(sb.toString());

	    oos.write(Float.toString(this.maxOrderCost));

	    sb = new StringBuilder();
	    sb.append("makeOrderAllert = ");
	    sb.append(makeOrderAllert);
	    oos.write(sb.toString());

	    sb = new StringBuilder();
	    sb.append("sendOrderAllert = ");
	    sb.append(sendOrdersAllert);
	    oos.write(sb.toString());

	    sb = new StringBuilder();
	    sb.append("menuUpdateAllert = ");
	    sb.append(menuUpdateAllert);
	    oos.write(sb.toString());
	    oos.close();

	} catch (IOException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	}
    }

}
